package com.adrian.misc.fractal.color;

import java.awt.Color;

public class SimpleColorMap extends ColorMap {
	Color[] colTable;

	
	public SimpleColorMap (String name, Color baseCol, Color startCol, Color endCol, int res) {
		super(name);
		this.baseCol = baseCol;
		resolution = res;
		colTable = new Color[res];
		
		double rInc = ((double)(endCol.getRed() - startCol.getRed()))/(double)res;
		double gInc = ((double)(endCol.getGreen() - startCol.getGreen()))/(double)res;
		double bInc = ((double)(endCol.getBlue() - startCol.getBlue()))/(double)res;
		System.out.println("StartCol:" + startCol + "," + endCol);
		System.out.println("Building color table: "+ res+"," + rInc + "," +gInc +"," + bInc);
		for (int i= 0; i < res; i++) {
			//System.out.println("Color:" +i);
			colTable[i] = new Color((int)(startCol.getRed() + i * rInc),
									(int)(startCol.getGreen() + i * gInc),
									(int)(startCol.getBlue() + i * bInc) );
		}
	}




	public Color getColor(double val) {
		int num = (int)( val * resolution);
		if ( num >= resolution) {
			return baseCol;
		}
		return colTable[num];
	}



}
